/**
 * 浮动提示
 * @author chenzhuangwei
 */
Ext.qtip = function(){
    var msgCt;

    function createBox(t, s){
        return ['<div class="msg-div">',
                '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
                '<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><h3>', t, '</h3>', s, '</div></div></div>',
                '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
                '</div>'].join('');
    }
    return {
    	/**
    	 * 浮动消息框
    	 * @param {String} title 标题
    	 * @param {String} format 内容
    	 * @param {Mixed} alignEl 对齐元素，默认为文档
    	 * @param {String} alignPosition 对齐位置,默认 br-br
    	 * @param {int} second 浮动秒数
    	 */
        tip : function(title, format, alignEl , alignPosition ,second ){
            if(!msgCt){
                msgCt = Ext.DomHelper.insertFirst(document.body,{ id:'msg-div' , cls : 'qtip-msg-div'} , true);
            }
            msgCt.alignTo(alignEl || document, alignPosition || 'br-br');//t-t
            var s = String.format.apply(String, Array.prototype.slice.call(arguments, 1));
            var m = Ext.DomHelper.append(msgCt, { html : createBox(title , s) }, true);
            m.slideIn('b').pause(second || 3).ghost('b',{ remove : true });//t
        },
        error : function(title, format, alignEl , alignPosition ){
        	this.tip(title, '<font color="red">' + format + '</font>', alignEl , alignPosition , 5);
        },
        msg : function(title, format, alignEl , alignPosition ){
			this.tip(title, format, alignEl , alignPosition );
        }
    };
}();
